package com.ugoodtech.mdcc.web.dto;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written by Stone Shaw, 16/3/7
 */


import com.ugoodtech.mdcc.core.Constants;
import com.ugoodtech.mdcc.core.domain.GeneralCode;
import com.ugoodtech.mdcc.core.utils.BeanUtilEx;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * 代码表
 */

public class GeneralCodeResponse implements Serializable {
    private Long generalCodeId;
    private String code;
    private String name;
    private GeneralCodeResponse parent;
    private Integer category;
    private boolean deleted;
    private Integer orderNum;
    private String nationCode;
    private String description;

    public Long getGeneralCodeId() {
        return generalCodeId;
    }

    public void setGeneralCodeId(Long generalCodeId) {
        this.generalCodeId = generalCodeId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public GeneralCodeResponse getParent() {
        return parent;
    }

    public void setParent(GeneralCodeResponse parent) {
        this.parent = parent;
    }

    public Integer getCategory() {
        return category;
    }

    public void setCategory(Integer category) {
        this.category = category;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }

    public String getNationCode() {
        return nationCode;
    }

    public void setNationCode(String nationCode) {
        this.nationCode = nationCode;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static GeneralCodeResponse turnGeneralCodeToResponse(GeneralCode generalCode) throws InvocationTargetException, IllegalAccessException {
        if (null != generalCode) {
            SimpleDateFormat defaultFormat = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
            GeneralCodeResponse generalCodeResponse = new GeneralCodeResponse();
            BeanUtilEx.copyProperties(generalCodeResponse, generalCode);
            generalCodeResponse.setGeneralCodeId(generalCode.getId());
            return generalCodeResponse;
        } else {
            return null;
        }
    }

    public static GeneralCode turnResponseToGeneralCode(GeneralCodeResponse generalCodeResponse) throws ParseException, InvocationTargetException, IllegalAccessException {
        if (null != generalCodeResponse) {
            SimpleDateFormat defaultFormat = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
            GeneralCode generalCode = new GeneralCode();
            BeanUtilEx.copyProperties(generalCode, generalCodeResponse);
            generalCode.setId(generalCodeResponse.getGeneralCodeId());
            return generalCode;
        } else {
            return null;
        }
    }
}
